from apps.blog.models import Category, Entry
from django.shortcuts import render_to_response
from django.views.generic.list import ListView
from django.views.generic.dates import  ArchiveIndexView, DateDetailView,\
    MonthArchiveView, YearArchiveView, DayArchiveView
from django.views.generic.detail import DetailView

def tag_list(request, tag):
    posts = [post for post in Entry.objects.all() if tag in post.get_tag_list()]
    return render_to_response('blog/tag_list.html', {'posts': posts, 'tag':tag})  

def author_list(request, author):
    posts = [post for post in Entry.online_objects.all() if post.author.username == author]
    return render_to_response('blog/auhtor_list.html', {'posts': posts, 'author':author})  

class Archive(ArchiveIndexView):
    queryset = Entry.online_objects.all()
    paginate_by = 10
    date_field = 'publication_date'

class Index(ListView):
    queryset = Entry.online_objects.all()
    paginate_by = 5
    
class CategoryDetail(DetailView):
    queryset = Category.online_objects.all()
    slug_field = 'slug'

class EntryDetail(DateDetailView):
    queryset=Entry.online_objects.all()
    month_format='%m'
    date_field='publication_date'
    slug_field='slug'
    
class BlogDay(DayArchiveView):
    queryset=Entry.online_objects.all()
    month_format='%m'
    date_field='publication_date'

class BlogMonth(MonthArchiveView):
    queryset=Entry.online_objects.all()
    month_format='%m'
    date_field='publication_date'

class BlogYear(YearArchiveView):
    queryset=Entry.online_objects.all()
    make_object_list=True
    date_field='publication_date'